// Author: Bjorn Schobben

#ifndef SLICE_H
#define SLICE_H

#include "Scalar.h"
#include "Pixel.h"
#include "Ray.h"
#include "Vector.h"
#include "Texture.h"

class Slice
{
	public:
		// Constructors/destructors
		Slice(unsigned int screenHeight);
		Slice(const Slice& rhs);
		virtual ~Slice();

		// Initialize slice buffer (and render it to a buffer)
		void Initialize(const Ray& ray, const Vector& nEyePoint, const World& world);

		// Get pixel from slice
		const Pixel& GetPixel(unsigned int y) const;

	private:
		void InitializePerspectiveBuffer();
		int Clip(int y);
		void SetupTextures(const Ray& ray, const World& world);
		void RenderSlice(const World& world);
		unsigned int CalculateTextureX(Ray::SideHit sideHit, const Vector& intersect, const Texture& texture);
		Cell::Side Slice::HitSideToCellSide(Ray::SideHit sideHit);


		// Screen height, pixel and perspective buffer
		unsigned int screenHeight;
		Scalar scalarScreenHeight;
		Pixel *sliceBuffer;
		Scalar *perspectiveBuffer;

		// These are just work variables
		int sliceStart, sliceEnd;
		int clippedSliceStart, clippedSliceEnd;
		Scalar wallDistance;
		Vector wallIntersection;
		Vector eyepoint;
		const Texture* wallTexture;
		const Texture* ceilingTexture;
		const Texture* floorTexture;
		unsigned int textureX, textureY;
		Scalar scalarWallHeight;
		unsigned int wallHeight;
};

#endif // SLICE_H
